<template>
  <div class="home-banner">
    <!-- 传入数据 开启自动轮播 -->
    <XtxSlider :sliders="sliders" :autoPlay="true" />
  </div>
</template>

<script>
import { findBanner } from '@/api/home.js'
import { onMounted, ref } from 'vue'
export default {
  name: 'HomeBanner',
  setup () {
    const sliders = ref([])

    onMounted(() => {
      async function loadBanner () {
        // 调用接口,获取数据
        const data = await findBanner()
        sliders.value = data.result
      }
      // 调用函数
      loadBanner()
    })
    return {
      sliders
    }
  }
  // data () {
  //   return {
  //     sliders: []
  //   }
  // },
  // async created () {
  //   const data = await findBanner()
  //   this.sliders = data.result
  // }
}
</script>

<style scoped lang='less'>
.home-banner {
  width: 1240px;
  height: 500px;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 98;
}
</style>
